<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true"
    CodeFile="ViewService.aspx.cs" Inherits="ViewService" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        window.onload = function() {
            TotalChkBx = parseInt('<%= this.gvService.Rows.Count %>');
            Counter = 0;
        }

        function SelectAll(CheckBox) {
            var TargetBaseControl = document.getElementById('<%= this.gvService.ClientID %>');
            var TargetChildControl = "chkselect";
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            var HeaderCheckBox = document.getElementById(HCheckBox);
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }         
    
    </script>

    <table width="100%">
        <tr>
            <td valign="middle" class="header">
                View Service
            </td>
        </tr>
    </table>
    <asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    <br />
    <asp:GridView ID="gvService" runat="server" DataKeyNames="ServiceID" AutoGenerateColumns="False"
        DataSourceID="ObjectDataSourceViewService" HeaderStyle-CssClass="smallheader"
        HeaderStyle-BackColor="#a9c0f2" BorderColor="#556CB0" GridLines="Vertical" AllowPaging="true"
        AllowSorting="false" OnPageIndexChanging="gridView_PageIndexChanging" OnSorting="gridView_Sorting"
        PageSize="2">
        <HeaderStyle HorizontalAlign="Center" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
         <%--<asp:TemplateField HeaderText="ID" SortExpression="ServiceID" ItemStyle-Width="30" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
                <ItemTemplate>
                    <b>
                        <asp:Label ID="lblServiceID" runat="server" Text='<%# Bind("ServiceID") %>' Width="20"></asp:Label></b>
                </ItemTemplate>
                <ItemStyle Width="110px"></ItemStyle>
            </asp:TemplateField>--%>
            <asp:TemplateField HeaderText="Image" SortExpression="ServiceImage" HeaderStyle-Width="100">
                <ItemTemplate>
                    <asp:Image ID="ImageService" runat="server" Height="100px" ImageUrl='<%# Eval("ServiceImage", "~/Images/Service/{0}") %>'
                        Width="100px" />
                </ItemTemplate>
                <HeaderStyle Width="100px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name" SortExpression="ServiceName" ItemStyle-Width="110">
                <ItemTemplate>
                    <b>
                        <asp:Label ID="lblServiceName" runat="server" Text='<%# Bind("ServiceName") %>' Width="100"></asp:Label></b>
                </ItemTemplate>
                <ItemStyle Width="110px"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description" SortExpression="Description" ItemStyle-Width="260">
                <ItemTemplate>
                    <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>' Width="250"></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="260px"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit" ItemStyle-Width="40">
                <ItemTemplate>
                    <div align="center">
                        <asp:HyperLink ID="HyperLinkEdit" runat="server" NavigateUrl='<%# Eval("ServiceID", "~/Pages_Admin/ManageService/EditService.aspx?id={0}") %>'
                            Text="Edit">
                        
                        </asp:HyperLink>
                    </div>
                </ItemTemplate>
                <ItemStyle Width="40px"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="20">
                <HeaderTemplate>
                    <asp:CheckBox ID="chkheader" runat="server" onclick="javascript:SelectAll(this);" />
                </HeaderTemplate>
                <ItemTemplate>
                    <div align="center">
                        <asp:CheckBox ID="chkselect" runat="server" ToolTip='<%# Eval("ServiceID") %>'/>
                    </div>
                </ItemTemplate>
                <ItemStyle Width="20px"></ItemStyle>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <br />
    <asp:ObjectDataSource ID="ObjectDataSourceViewService" runat="server" DeleteMethod="DeleteService"
        OldValuesParameterFormatString="original_{0}" SelectMethod="ListService" TypeName="DALService">
        <DeleteParameters>
            <asp:Parameter Name="ServiceID" Type="String" />
        </DeleteParameters>
       
    </asp:ObjectDataSource>
    <div align="left">
        <asp:Button ID="btnAddService" runat="server" Text="Add new service" 
            onclick="btnAddService_Click" />
        <asp:Button ID="btnDeleteService" runat="server" Text="Delete selected services"
            OnClick="btnDeleteService_Click" 
            onclientclick="return confirm(&quot;Are you sure you want to delete selected service?&quot;);" />
    </div>
</asp:Content>
